let data =JSON.parse(localStorage.getItem("data_list"))
let Data = JSON.parse(localStorage.getItem("Data_list"))

// const biaoti = document.querySelector('.biaoti p')
// const shijian = document.querySelector('.shijian p')
// const zhuangtai = document.querySelector('.zhuangtai p')
const questionaire = document.querySelector('.questionaire')

function initData(data_temp){
    // biaoti.textContent=data.title
    // shijian.textContent=data.deadline
    // zhuangtai.textContent=data.state
    let aire = document.createElement('div')
    let Hr = document.createElement('hr')
    aire.innerHTML = "<div class='checkbox' id='" + data_temp.id +"checkbox'>"
        + "            <input type = 'radio' id='" + data_temp.id +"radio'>"
        +"                </div >"
        + "                <div class='title' id='" + data_temp.id +"title'>"
        +"                    <p>"+data_temp.title+"</p>"
        +"                </div>"
        + "                <div class='time' id='" + data_temp.id +"time'>"
        +"                    <p>"+data_temp.deadline+"</p>"
        +"                </div>"
        + "                <div class='state'>"
        +"                    <p id='" + data_temp.id +"state'>"+data_temp.state+"</p>"
        +"                </div>"
        +"                <div class='operation'>"
        +"                    <button onclick=''>填写</button>"
        +"                    <button onclick='reEdit()'>编辑</button>"
        +"                    <button onclick='DEL()'>删除</button>"
        +"                    <button>查看数据</button>"
        +"                </div>"
        questionaire.appendChild(aire)
        questionaire.appendChild(Hr)
        if(data_temp.state=="发布中"){
            this.Id=data_temp.id
            document.getElementById('' + this.Id + "state").style.color ="#07c160"
        }
}

function newFile(){
    window.location.href = "./edit.html"
}

function reEdit(){
    window.history.go(-1)
}

function Delete_first() {
    document.querySelector('.first').style.display="none"
    document.querySelector('hr').style.display = "none"
}

let flag
// 删除答卷
function DEL(n){
    document.querySelector(".Kill").style.setProperty('display','block')
    flag=n
    if(n=="all"){
        localStorage.removeItem("Data_list")
    }
}
document.querySelector(".yes").addEventListener("click",Display)
function Display(){
    document.querySelector(".Kill").style.setProperty('display','none');
    if(flag=="all"){
        alert("当前无问卷")
        window.location.href="../index.html"
    }
    else if(flag==0){
        Delete_first()
    }
}
document.querySelector(".no").addEventListener("click",Display1)
function Display1(){
    document.querySelector(".Kill").style.setProperty('display','none');
}

// questionaire.addEventListener('click',initData(Data.list[0].updata))
function initList(){
    Data = JSON.parse(localStorage.getItem("Data_list"))
    for(i=0;i<Data.list.length;i++){
        initData(Data.list[i].updata)
    }
}
questionaire.addEventListener('click',initList())
